<?
include("./_common.php");
include("$g4[path]/lib/shop.lib.php");
include_once("$g4[path]/head.sub.php");
if($OID!="")
{
	$shop = get_shop();
	$order_row = mysql_fetch_array(mysql_query("select * from g4_order where oid='".$OID."' limit 1"));
}
else
{
	echo("<script>alert('잘못된 접속입니다.');self.close();</script>");
}
?>
<html>
<head>
<title>주문내역</title>
<script language="javascript" src="<?=$g4['path']?>/js/common.js"></script>
<script language="javascript" src="<?=$g4['path']?>/js/jquery.js"></script>
<script language="javascript" src="<?=$g4['path']?>/js/sideview.js"></script>
<link rel="stylesheet" href="<?=$g4['admin_path']?>/admin.style.css" type="text/css">
<style>
body{padding:10px;margin:0px}
.sTitle{font-size:16px;font-weight:bold;color:#000066}
.index1{color:#000000;padding-left:10px;background:#EFEFFF}
.index2{color:#000000;background:#EFEFFF}
</style>
<script>
function ShowHistory(ID)
{
	if(document.all(ID).style.display=='none')
	{
		document.all(ID).style.display="inline";
	}
	else
	{
		document.all(ID).style.display='none';
	}
}

function frmCheck()
{
	var frm = document.orderFrm;

	if(frm.status.value == "4" && (frm.tranc.value=="" || frm.tranc_num.value==""))
	{
		alert("배송정보를 입력하세요.");
		frm.tranc.focus();
	}
	else
	{
		if(confirm("수정 하시겠습니까?"))
		{
			frm.submit();
		}
		else
		{
			return false;
		}
	}
}
</script>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<form name="orderFrm" method="post" action="order_status_change.php">
<input type="hidden" name="OID" value="<?=$order_row[oid]?>">
	<tr>
		<td>
			<span class="sTitle"><li>주문내역</li></span>
			<table cellpadding="3" cellspacing="0" border="0" width="100%" style="border:solid 1px #D7D7D7">
				<colgroup>
					<col width="40">
					<col width="120">
					<col width="">
					<col width="100">
					<col width="60">
					<col width="60">
					<col width="60">
					<col width="80">
				</colgroup>
				<tr align="center">
					<td class="index2">순번</td>
					<td class="index2">상품코드</td>
					<td class="index2">상품명</td>
					<td class="index2">옵션</td>
					<td class="index2">배송정책</td>
					<td class="index2">단가</td>
					<td class="index2">수량</td>
					<td class="index2">합계</td>
				</tr>
				<tr><td colspan="7" height="1" bgcolor="#D7D7D7"></td></tr>
			<?
			$order_goods_sql = "select * from g4_order_goods where oid='".$OID."'";
			$order_goods_rst = mysql_query($order_goods_sql);
			$goods_no = 1;
			$total_price = 0;
			$total_tranc = $shop[tranc_price];
			while($order_goods = mysql_fetch_array($order_goods_rst))
			{
				$g_option = explode("|",$order_goods[g_option]);
			?>
				<tr align="center" height="50">
					<td><?=number_format($goods_no);?></td>
					<td><?=$order_goods[g_code]?></td>
					<td align="left"><?=$order_goods[g_name]?></td>
					<td><?if($g_option[0]!=""){?><?=$g_option[0]?>(+<?=number_format($g_option[1])?>원)<?}?></td>
					<td><?=get_tranc2($order_goods[g_tranc])?></td>
					<td align="right"><?=number_format($order_goods[g_price])?>원</td>
					<td><?=number_format($order_goods[cnt])?></td>
					<td align="right"><?=number_format($order_goods[tot_price])?>원</td>
				</tr>
				<tr><td colspan="8" height="1" bgcolor="#D7D7D7"></td></tr>
			<?
				$goods_no++;
				$total_price+= $order_goods[tot_price];
				if($total_price >= $shop[tranc_if] || $order_goods[g_tranc] == "N" || $order_goods[g_tranc] == "C")
				{
					$total_tranc = 0;
				}
			}
			?>
				<tr align="right">
					<td colspan="4" style="font-size:14px;color:#000099;font-weight:bold">배송비 : <?=number_format($total_tranc)?>원</td>
					<td colspan="3" style="font-size:14px;color:#990000;font-weight:bold">총상품금액 : <?=number_format($total_price)?>원</td>
				</tr>
			</table>
			<br>
			<span class="sTitle"><li>결제내역</li></span>(ⓓ = ⓐ + ⓑ - ⓒ)
			<table cellpadding="3" cellspacing="0" border="0" width="100%" style="border:solid 1px #D7D7D7">
				<colgroup>
					<col width="100">
					<col width="">
				</colgroup>
				<tr>
					<td class="index1">상품총액ⓐ</td>
					<td><span style="width:120px;text-align:right"><?=number_format($order_row[pay_price])?>원</span></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">배송비ⓑ</td>
					<td><span style="width:120px;text-align:right"><?=number_format($order_row[pay_tranc])?>원</span></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">포인트결제ⓒ</td>
					<td><span style="width:120px;text-align:right"><?=number_format($order_row[pay_point])?>원</span></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">실결제금액ⓓ</td>
					<td><span style="width:120px;text-align:right;color:#FF0000"><?=number_format($order_row[pay_amount])?>원</span></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">결제방법</td>
					<td><?=get_paymethod($order_row[pay_method])?><?if($order_row[pay_info]!=""){?><br>(<?=$order_row[pay_info]?>)<?}?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">상태</td>
					<td>
					<select name="status">
						<?for($i=0;$i<=8;$i++){?>
						<option value="<?=$i?>" <?if($i == $order_row[status]){echo("selected");}?>><?=get_status($i)?></option>
						<?}?>
					</select>
					<button class="btn1" style="cursor:pointer" onclick="ShowHistory('<?=$order_row[oid]?>')">상태변경내역</button>
					<DIV style="position:absolute;display:none;" id="<?=$order_row[oid]?>">
					<table cellpadding="5" cellspacing="1" border="0" width="250" bgcolor="#CCCCCC" style="position:absolute;left:-150px;top:+20px">
					<?
					$tmp_status_history = explode("/",$order_row[status_history]);
					for($i=0;$i<count($tmp_status_history);$i++)
					{
						$tmp_history = explode("|",$tmp_status_history[$i]);
						?>
						<tr bgcolor="#FFFFFF">
							<td><?=number_format($i+1)?></td>
							<td><?=get_status($tmp_history[0]);?></td>
							<td><?=$tmp_history[1]?></td>
						</tr>
						<?
					}
					?>
					</table>
					</DIV>
					</td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">배송</td>
					<td>
					택배사 : <input type="text" class="ed" style="width:160px" name="tranc" value="<?=$order_row[tranc]?>">&nbsp;&nbsp;
					송장번호 : <input type="text" class="ed" style="width:250px" name="tranc_num" value="<?=$order_row[tranc_num]?>">
					</td>
				</tr>
			</table>
			<br>
			<span class="sTitle"><li>배송정보</li></span>
			<table cellpadding="3" cellspacing="0" border="0" width="100%" style="border:solid 1px #D7D7D7">
				<colgroup>
					<col width="100">
					<col width="">
				</colgroup>
				<tr>
					<td colspan="2" bgcolor="#D7D7D7" style="color:#000000;font-weight:bold">주문자정보</td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">주문자명</td>
					<td><?=$order_row[o_name]?>&nbsp;<?if($order_row[mb_part]=="member"){?>(회원 : <?=$order_row[mb_id]?>)<?}else{?>(비회원)<?}?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">주문자 E-mail</td>
					<td><?=$order_row[o_email]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">주문자 전화번호</td>
					<td><?=$order_row[o_tel]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">주문자 휴대폰</td>
					<td><?=$order_row[o_hp]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">주문자 주소</td>
					<td>[<?=$order_row[o_zip]?>]<?=$order_row[o_addr1]?>&nbsp;<?=$order_row[o_addr2]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td colspan="2" bgcolor="#D7D7D7" style="color:#000000;font-weight:bold">수령자정보</td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">수령자명</td>
					<td><?=$order_row[s_name]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">수령자 E-mail</td>
					<td><?=$order_row[s_email]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">수령자 전화번호</td>
					<td><?=$order_row[s_tel]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">수령자 휴대폰</td>
					<td><?=$order_row[s_hp]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">수령자 주소</td>
					<td>[<?=$order_row[s_zip]?>]<?=$order_row[s_addr1]?>&nbsp;<?=$order_row[s_addr2]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr height="50">
					<td class="index1">요구사항</td>
					<td><?=$order_row[s_memo]?></td>
				</tr>
				<tr><td colspan="2" height="1" bgcolor="#D7D7D7"></td></tr>
				<tr>
					<td class="index1">주문일자</td>
					<td><?=$order_row[buy_datetime]?></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td height="50" align="center">
		<button class="btn1" style="width:80px;height:30px;cursor:pointer" onclick="frmCheck();">수정</button>&nbsp;
		<button class="btn1" style="width:80px;height:30px;cursor:pointer" onclick="self.close();">닫기</button>&nbsp;
		<button class="btn1" style="width:80px;height:30px;cursor:pointer" onclick="print();">출력</button>
		</td>
	</tr>
</form>
</table>
</body>
</html>